ssc install binscatter

use "${pathdata_baseline}/StatisticsQualitativeContent.dta", clear

preserve
* ### Belief Movement: Main Table ###	

* Step 1: Clone the dataset
gen _clone = 1

* Step 2: Replace the values
* For the cloned dataset
replace effect = abs * 100 if _clone == 1
replace effect_recall = abs * 100 if _clone == 1
replace treatment = "bayesian_movement_stat_with_context" if _clone == 1 & inlist(treatment, "n>1_context")
replace treatment = "bayesian_movement_statistic" if _clone == 1 & inlist(treatment, "n>1_nocontext")

duplicates drop

* Step 3: Append the cloned dataset to the original one
append using "${pathdata_baseline}/StatisticsQualitativeContent.dta", gen(_source)

*keep effect effect_recall bayesian_movement treatment prolific_pid 

gen temp_group = 0 if inlist(treatment, "n>1_context")
replace temp_group = 1 if inlist(treatment, "n>1_nocontext")
replace temp_group = 2 if inlist(treatment, "bayesian_movement_stat_with_context")
replace temp_group = 3 if inlist(treatment, "bayesian_movement_statistic")
keep if story_type=="consistent"
bysort prolific_pid : drop if _N==1

drop if treatment == "noinfo"

collapse (mean) effect effect_recall (sem) imm_sem = effect del_sem = effect_recall, by(temp_group)	 
rename imm_sem sem0
rename del_sem sem1
rename effect dev0
rename effect_recall dev1
reshape long sem dev, i(temp_group) j(delay)
gen upper=dev+sem
gen lower=dev-sem

tw (scatter dev delay if temp_group == 0, connect(l) lcolor(black*0.5) lpattern(solid) msize(large) ms(d) mcolor(black*0.5)) ///
    (scatter dev delay if temp_group == 1, connect(l) lcolor(black*1.5) lpattern(shortdash) msize(large) ms(o) mcolor(black*1.5)) ///
    (scatter dev delay if temp_group == 2, connect(l) lcolor(black*0.5) lpattern(dash_dot) msize(0.0001) ms(d) mcolor(black*0.5)) ///
    (scatter dev delay if temp_group == 3, connect(l) lcolor(black*1.5) lpattern(longdash) msize(0.0001) ms(o) mcolor(black*1.5)) ///
    (rcap upper lower delay if temp_group == 0, lw(medthick) lcolor(black*0.5)) ///
    (rcap upper lower delay if temp_group == 1, lw(medthick) lcolor(black*1.5)), ///
    ytitle("Mean belief impact {c 177} SEM" "(percentage points)") ///
    xtitle(" ") xsc(r(-0.5 1.5) lcolor(none)) ysc(r(0 20) lcolor(none)) ///
    yline(0, lcolor(gs10) lwidth(thin)) ///
    graphregion(color(white)) title("Belief impact in {it:Immediate} and {it:Delay}", margin(b=3) color(black)) ///
    ylabel(0 5 10 15 20, tlc(none) angle(0) glcolor(gs15) glwidth(thin)) ///
    legend(order(1 2 3 4) label(1 " " "Statistic With" "Qualitative Content" ) label(2 " " "Statistic" " ") label(3 "Bayesian Benchmark:" "Statistic With" "Qualitative Content") label(4 " " "Bayesian Benchmark:" "Statistic" ) r(1)) ///
    xlabel(0 "Immediate" 1 "1-day delay") ysize(5) xsize(10)
graph export "${pathout_baseline}/figures/figure3a.pdf", replace

restore










* Combined Recall

preserve




	collapse (mean) correct_recall (sem) stderr = correct_recall, by (treatment)
rename correct_recall  dev
gen upper = dev + stderr
gen lower = dev - stderr


egen treatment_num = group(treatment)

tw (scatter dev treatment_num if treatment == "n>1_context", connect(l) mcolor(black*0.5) ms(d) msize(large)) ///
   (scatter dev treatment_num if treatment =="n>1_nocontext" , connect(l) mcolor(black*1.5) ms(o) msize(large)) ///
   (rcap upper lower treatment_num if treatment == "n>1_context", lw(medthick) lcolor(black*0.5)) ///
   (rcap upper lower treatment_num if treatment == "n>1_nocontext", lw(medthick) lcolor(black*1.5)), ///
	graphregion(color(white)) ysc(r(0 0.8)) ylab(0(0.1)0.8, angle(horizontal) tlc(none)  glcolor(gs15) glwidth(thin))  ysc(lcolor(none))  xsc(r(0.5 2.5) lcolor(none)) ///
		 		yline(0, lcolor(gs10) lwidth(thin)) ///
	 	title("Correct recall of information type and valence",  color(black)) ysize(5) xsize(10) ///
xlab(1 "Statistic With Qualitative Content" 2 "Statistic" ,valuelabel) xtitle("Condition") ytitle(" " "Mean Rate  {c 177} SEM") leg(off)
	graph export "${pathout_baseline}/figures/figure3b.pdf", replace

restore
